# Tanım: Ücretsiz GTK2 çapraz platform dosya arşivleyici (kaynaktan derler)
# URL: http://peazip.org
# Paketçi: yasarciv67
# Gerekler: lazarus-gtk2 icoutils gtk2 desktop-file-utils balz lpaq paq8o p7zip upx zpaq quad unace

isim=peazip-kaynak
surum=6.5.1
devir=1
kaynak=(https://github.com/giorgiotani/PeaZip/releases/download/$surum/peazip-$surum.src.zip
https://aur.archlinux.org/cgit/aur.git/plain/peazip.install?h=peazip-gtk2-build)

derle() {
  cd peazip-$surum.src
  lazbuild --lazarusdir=/usr/lib/lazarus --widgetset=gtk2 --build-all project_pea.lpi && [ -f pea ]
  lazbuild --lazarusdir=/usr/lib/lazarus --widgetset=gtk2 --build-all project_gwrap.lpi && [ -f pealauncher ]
  lazbuild --lazarusdir=/usr/lib/lazarus --widgetset=gtk2 --build-all project_peach.lpi && [ -f peazip ]
  icotool -x -w 256 "$SRC/peazip-$surum.src/res/icons/PeaZip.ico" -o "$SRC/peazip.png"

  _pkgres="$PKG/opt/peazip/res"
  install -Dm755 "$SRC/peazip-$surum.src/peazip" "$PKG/opt/peazip/peazip"
  install -Dm755 "$SRC/peazip-$surum.src/pea" "$_pkgres/pea"
  install -Dm755 "$SRC/peazip-$surum.src/pealauncher" "$_pkgres/pealauncher"
  install -Dm644 "$SRC/peazip.png" "$PKG/usr/share/pixmaps/peazip.png"

  cd "$SRC/peazip-$surum.src/res"
  for _file in *.txt icons/*.ico lang/* themes/{*-embedded/*,*.7z}; do
    _octal=$(stat -c "%a" "$_file")
    install -Dm"${_octal}" "$_file" "$_pkgres/$_file"
  done
  cd $SRC

  ln -sf -T "/usr/lib/p7zip" "$_pkgres/7z"
  for _file in arc/{arc,marc} quad/{balz,quad} lpaq/lpaq8 paq/paq8o unace/unace upx/upx zpaq/zpaq; do
    install -d "$_pkgres/$(dirname $_file)/"
    ln -sf -T "/usr/bin/$(basename $_file)" "$_pkgres/$_file"
  done

  install -d "$PKG/usr/bin/"
  for _file in /opt/peazip/{peazip,res/pea,res/pealauncher}; do
    ln -sf "$_file" "$PKG/usr/bin/$(basename $_file)"
  done

  desktop-file-install --dir="$PKG/usr/share/applications/" --set-icon="peazip"\
  --remove-key="Name[en_US]" "$SRC/peazip-$surum.src/FreeDesktop_integration/peazip.desktop"
}
